//
//  AllRecordPointVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/10/27.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "AllRecordPointVC.h"
#import "CityTourLinePointCell.h"
@interface AllRecordPointVC ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong)UICollectionView * allPointCollectionView;
@property (nonatomic, strong)NSMutableArray * dataSource;
@end

@implementation AllRecordPointVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self loadData];
}

- (void)setupUI {
    
    self.barBGAlpha = 1;
    
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.allPointCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10,kNavigationBarHeight,SCREEN_WIDTH - 20, SCREEN_HEIGHT - kNavigationBarHeight) collectionViewLayout:layout];
    self.allPointCollectionView.showsVerticalScrollIndicator = NO;
    self.allPointCollectionView.backgroundColor = [UIColor whiteColor];
    self.allPointCollectionView.delegate = self;
    self.allPointCollectionView.dataSource = self;
    [self.view addSubview:self.allPointCollectionView];
    
    [self.allPointCollectionView registerNib:[UINib nibWithNibName:@"CityTourLinePointCell" bundle:nil] forCellWithReuseIdentifier:@"CityTourLinePointCell"];
}

- (void)loadData {
    
    self.dataSource = [NSMutableArray arrayWithArray:self.lineModel.records];
    
    if (self.dataSource.count > 0) {
        [self.dataSource removeObjectAtIndex:0];
    }
    
    self.title = self.lineModel.linename;
    [self.allPointCollectionView reloadData];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CityTourLinePointCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CityTourLinePointCell" forIndexPath:indexPath];
    
    cell.select = NO;
    
    ScenicPoint * model = self.dataSource[indexPath.row];
    [cell setPlayCellData:model];
    cell.maskView.hidden = YES;
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(10, 5, 0, 5);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat w = (SCREEN_WIDTH - 62)/4;
    return CGSizeMake(w, w + 35);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
